package com.crm.service.impl.customerManager;

import com.crm.common.model.Enum.StatusCodeEnum;
import com.crm.dao.mapper.customerManager.CustomerPoolCompanyMapper;
import com.crm.model.entity.customerManager.CustomerPoolCompany;
import com.crm.model.entity.customerManager.CustomerPoolCompanyExample;
import com.crm.service.customerManager.CustomerPoolCompanyDbService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;

/**
 * @ Author ：pym
 * @ Date   ：2021/1/17 15:02
 */
@Service
public class CustomerPoolCompanyDbServiceImpl implements CustomerPoolCompanyDbService {
    @Autowired
    CustomerPoolCompanyMapper customerPoolCompanyMapper;

    @Override
    public Boolean insertCustomerPoolCompany(CustomerPoolCompany customerPoolCompany) {
        Boolean result = false;
        int num = customerPoolCompanyMapper.insertSelective(customerPoolCompany);
        if(num>0){
            result = true;
        }
        return result;
    }

    @Override
    public List<CustomerPoolCompany> selectCompanyByCustomerPoolId(String customerPoolId) {
        CustomerPoolCompanyExample customerPoolCompanyExample = new CustomerPoolCompanyExample();
        CustomerPoolCompanyExample.Criteria criteria = customerPoolCompanyExample.createCriteria();
        criteria.andCustomerPoolIdEqualTo(customerPoolId);
        criteria.andDeleteStatusEqualTo(Short.parseShort(String.valueOf(StatusCodeEnum.NORMAL_CODE.getState())));
        List<CustomerPoolCompany> customerPoolCompanyList = customerPoolCompanyMapper.selectByExample(customerPoolCompanyExample);
        return customerPoolCompanyList;
    }

    @Override
    public Boolean deleteCustomerPoolCompanyByCluePoolId(String customerPoolId) {
        CustomerPoolCompanyExample customerPoolCompanyExample = new CustomerPoolCompanyExample();
        CustomerPoolCompanyExample.Criteria criteria = customerPoolCompanyExample.createCriteria();
        criteria.andCustomerPoolIdEqualTo(customerPoolId);
        CustomerPoolCompany customerPoolCompany = new CustomerPoolCompany();
        customerPoolCompany.setDeleteStatus(Short.parseShort(String.valueOf(StatusCodeEnum.DELETE_CODE.getState())));
        return customerPoolCompanyMapper.updateByExampleSelective(customerPoolCompany, customerPoolCompanyExample) > 0;
    }
}
